export default {
	namespaced: true, //命名空间必须写
	state: {
		audioSrc: "569823888",
		// 存放全局事件
		events: []
	},
	mutations: {
		changeAudioSrc(state, src) {
			console.log('src', src);
			state.audioSrc = src;
		},
		// 注册全局事件
		regEvent(state, event) {
			state.events.push(event);
		},
		// 执行全局事件
		doEvent(state, params) {
			state.events.forEach(e => {
				e(params);
			})
		},
		//注销实践
		removeEvent(state, event) {
			let index = state.events.findIndex(item => {
				return item === event;
			})
			if (index !== -1) {
				state.events.splice(index, 1);
			}
		}
	},
	// 异步方法
	actions: {
		// 分发注册全局事件
		$audioOn({
			commit
		}, event) {
			commit('regEvent', event);
		},
		// 分发执行全局事件
		$audioEmit({
			commit
		}, params) {
			commit('doEvent', params);
		},
		// 分发注销全局事件
		$audioRemoveEvent({
			commit
		}, event) {
			commit('removeEvent', event);
		}
	}
}